package com.citusdata.elven.feeder;

import com.citusdata.elven.datastore.BdbDatastore;
import com.citusdata.elven.feeder.HttpRpcDataFeeder;
import com.citusdata.elven.feeder.Log4jHelper;
import com.citusdata.elven.httpRpc.HttpRpcServer;
import com.citusdata.elven.linearRoad.LinearRoadService;
import org.apache.log4j.Logger;


public class LinearRoadServer {
  static { Log4jHelper.setApplicationName(LinearRoadServer.class); } 
  private static final Logger logger = Logger.getLogger(LinearRoadServer.class);

  public static void main(String[] args) {
    if (args.length < 1) {
      logger.fatal("Usage: LinearRoadServer database_dir");
      System.exit(-1);
    }

    String datastorePath = args[0];
    BdbDatastore datastore = new BdbDatastore(datastorePath);

    HttpRpcServer httpRpcServer = HttpRpcDataFeeder.getHttpRpcServer();
    httpRpcServer.registerService(new LinearRoadService());
    httpRpcServer.registerService(datastore);
    httpRpcServer.run();  // run() returns when the server is shut down

    datastore.close();    // close the datastore
  }
}
